//
//  ljjiftAlert.ljjift
//  AiTouYun
//
//  Created by liujunjie on 2018/9/15.
//  Copyright © 2018年 junjie.liu. All rights reserved.
//

import UIKit

public typealias actionTrue = (_ action: UIAlertAction) -> ()
public typealias actionCancel = (_ action: UIAlertAction) -> ()

public extension UIAlertController {
    
    /* 中间的弹框,可点击 : 标题 + 2个按钮 +1个确定按钮的点击事件*/
     public static func ljj_alertCustomOne(title: String, message: String, cancelTitle: String, actionTitle: String, viewControllers: AnyObject,alertTrue: @escaping actionTrue){
        
        let alertV = UIAlertController(title: title, message: message, preferredStyle: .alert)
        
        let cancelAction = UIAlertAction(title: cancelTitle, style: .cancel) { (action) in
            alertV.dismiss(animated: true, completion: nil)
        }
        alertV.addAction(cancelAction)
        
        let trueAction = UIAlertAction(title: actionTitle, style: .default, handler: alertTrue)
        alertV.addAction(trueAction)
        
        viewControllers.present(alertV, animated: true, completion: nil)
    }
    
    /*中间的弹框 : 标题 + 两个按钮 + 2个按钮分别的点击事件*/
    public static func ljj_alertCustomTwo(title: String, message: String, cancelTitle: String, trueTitle:NSString, viewController: AnyObject ,cancelHandler: @escaping actionCancel, trueAction: @escaping actionTrue){
        
        let alertV = UIAlertController(title: title, message: message, preferredStyle: .alert)
        
        let cancelAction = UIAlertAction(title: cancelTitle, style: .cancel, handler: cancelHandler)
        alertV.addAction(cancelAction)
        
        let trueAction = UIAlertAction(title: trueTitle as String, style: .default, handler: trueAction)
        alertV.addAction(trueAction)
        viewController.present(alertV, animated: true, completion: nil)
    }
    
    /*中间的弹框 : 标题 + 一个按钮*/
    public static func ljj_alertCustomThree(title: String, message: String, cancleTitle: String, viewController: UIViewController,cancleAction:@escaping actionCancel) {
        
        let alertV = UIAlertController(title: title, message: message, preferredStyle: .alert)
        
        let cancelAction = UIAlertAction(title: cancleTitle, style: .cancel, handler: cancleAction)
        alertV.addAction(cancelAction)
        
        viewController.present(alertV, animated: true, completion: nil)
    }
    
    /*底部弹框*/
    public static func ljj_alertCustomFour(title: String, message: String, oneActionTitle: String, twoActionTitle: String, viewController: UIViewController, oneActionBlock:@escaping actionTrue, twoActionBlock:@escaping actionCancel){
        
        let alertV = UIAlertController(title: title, message: message, preferredStyle: .actionSheet)
        
        let oneCancelAction = UIAlertAction(title: oneActionTitle, style: .default, handler: oneActionBlock)
        alertV.addAction(oneCancelAction)
        
        let twoCancelAction = UIAlertAction(title: twoActionTitle, style: .default, handler: twoActionBlock)
        alertV.addAction(twoCancelAction)
        
        let actionAction = UIAlertAction(title: "取消", style: .default) { (make) in
            alertV.dismiss(animated: true, completion: nil)
        }
        alertV.addAction(actionAction)
        
        viewController.present(alertV, animated: true, completion: nil)
    }
    
    /*中间弹出的一条消息*/
    public static func ljj_alertCustomFive(viewController: UIViewController, message: String){
        
        let alertV = UIAlertController(title: "", message: message, preferredStyle: .alert)
        
        viewController.present(alertV, animated: true, completion: nil)
        
        alertV.perform(#selector(Dissmiss), with: nil, afterDelay: 1.5)
    }
    
    @objc fileprivate func Dissmiss() {
        self.dismiss(animated: true, completion: nil)
    }
    
}
